package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.GoodsType;
import com.atguigu.jxc.service.GoodsTypeService;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("goodsType")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    // http://localhost:8080/goodsType/loadGoodsType
    /**
     * 查询商品所有分类
     * @return
     */
    @PostMapping("loadGoodsType")
    public List<Map> loadGoodsType(){
        List<Map> list = goodsTypeService.loadGoodsType();

        return  list;
    }

    // http://localhost:8080/goodsType/save
    /**
     * 新增分类
     * @param goodsTypeName
     * @param pId
     * @return
     */
    @PostMapping("save")
    public ServiceVO save(String goodsTypeName,Integer pId){
        goodsTypeService.save(goodsTypeName,pId);
        return new ServiceVO(100,"请求成功");
    }

    // http://localhost:8080/goodsType/delete
    @PostMapping("delete")
    public ServiceVO delete(Integer goodsTypeId){
        goodsTypeService.delete(goodsTypeId);
        return new ServiceVO(100,"请求成功");
    }
}
